#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	int arr[30][30] = { 0 };
	int m = 0;
	int n = 0;
	scanf("%d %d", &m, &n);
	int up = 0;
	int down = m - 1;
	int left = 0;
	int right = n - 1;
	int i = 0;
	int j = 0;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			scanf("%d", &arr[i][j]);
		}
	}
	while (1)
	{
		for (i = left; i <= right; i++)
		{
			printf("%d ", arr[up][i]);
		}
		if (++up > down)
		{
			break;
		}
		for (i = up; i <= down; i++)
		{
			printf("%d ", arr[i][right]);
		}
		if (--right < left)
		{
			break;
		}
		for (i = right; i >= left; i--)
		{
			printf("%d ", arr[down][i]);
		}
		if (--down < up)
		{
			break;
		}
		for (i = down; i >= up; i--)
		{
			printf("%d ", arr[i][left]);
		}
		if (++left >= right)
		{
			break;
		}
	}
	return 0;
}